package org.ttitfly.ttcore.web.account;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.ttitfly.ttcore.entity.account.Resource;
import org.ttitfly.ttcore.service.account.ResourceManager;
import org.ttitfly.ttcore.util.tree.TreeNode;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class GetResourceTreeChildrenAction extends ActionSupport{
	String key;
	List<TreeNode> children = new ArrayList<TreeNode>();
	@Autowired
	private ResourceManager resourceManager;
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public List<TreeNode> getChildren() {
		return children;
	}
	public void setChildren(List<TreeNode> children) {
		this.children = children;
	}
	
	
	
	public String execute(){
		Long nt = Long.parseLong(key);
		if(nt == 0){
			List<Resource> list = resourceManager.findAll();
			for(Resource resource : list){
				TreeNode node = new TreeNode(""+resource.getId(),resource.getTitle(),true);
				children.add(node);
			}
		}
		
		return SUCCESS;
	}
	
	
}

